<?php
/**
 * --------------------------------------------------------------------
 * MCore框架
 * 作者：阿枫，QQ：52037872，Email：nczy520@gmail.com
 * --------------------------------------------------------------------
 *
 * SVN revision information:
 * @version $Revision: 50 $:
 * @author  $Author: zy $:
 * @date      $Date: 2013-11-09 19:34:15 +0800 (星期六, 09 十一月 2013) $:
 * @url         $HeadURL: svn://vps.mdeve.com/web_mcore/manage/function/global.func.php $:
 */

class _PersonalClass extends __basic_def {

    // 修改密码
    function _chnpwd() {
        global $_M;

        $breadcrumb = array(
            "个人资料" => "#",
            "修改登陆密码" => "",
        );

        $_M->template();
        $_M->template->load(MANAGE_PATH. "/templates/personal/chnpwd");
        $_M->template->insert_html(_generate_breadcrumb($breadcrumb));
        $_M->template->display();
    }

    function _chnpwd_save () {
        global $_M;

        $pass1 = $_POST["pass1"] ?? "";
        $pass2 = $_POST["pass2"] ?? "";
        $pass3 = $_POST["pass3"] ?? "";

        // 检查参数
        if(strlen($pass1)!=32 || strlen($pass2)!=32 || strlen($pass3)!=32) ajax_result("error", "修改密码失败，密码格式错误！");
        if($pass2 != $pass3) ajax_result("error", "修改密码失败，新密码和确认密码不一致！");

        if($_M->cfg["module_enable"]) module_insert_code('manage_personal_chnpwd_proc');

        // 检验密码
        require_once CORE_PATH. '/class/drivers/PasswordHash.php';
        $hasher = new PasswordHash(8, false);
        $result = $hasher->CheckPassword($pass1, $_M->userinfo["pass"]);
        if(!$result) ajax_result("error", "原密码验证失败！");

        $pass_en = $hasher->HashPassword($pass2);

        $_M->db();
        $_M->db->update(array("pass"=>$pass_en), array("table"=>"user", "where"=>"id={$_M->userinfo["id"]}"));

        ajax_result("successful");

    }

}